package xyz.fefine;

import java.util.List;

/**
 * Created by feng_ on 2016/9/8.
 *  " - " primary
 */
public class NegativeExpr extends ASTList {
    public NegativeExpr(List<ASTree> list) {
        super(list);
    }

    @Override
    public Object eval(Enviorment enviorment) {
        Object o = operand().eval(enviorment);
        if (o instanceof Integer) {
            return new Integer(-(Integer)o);
        }else{
            throw new StoneException("bad type of -"+operand(),this);
        }
    }

    public ASTree operand() {
        return child(0);
    }

    @Override
    public String toString() {
        return "-"+operand();
    }
}
